// pages/shop_list/shop_list.js
// pages/share/share.js
var api = require('../../config/api.js');
var util = require('../../utils/util.js');


Page({

  /**
   * 页面的初始数据
   */
  data: {
    value:"",
    id:'',
    one:true,//综合
    two:0,//按价格
    three:0,//按销量
  },

  // 获取店铺信息
  getDrandIndex(id) {
    var that = this;
    util.request(api.DrandIndex, {
      brandId:id
    }, 'get').then(function (res) {
      if (res.errno === 0) {
        that.setData({
          brand:res.data.brandInfo,
          value:res.data.brandInfo.star,
          goodsList:res.data.goods,
          detail:res.data.brandInfo.detail
        })
        wx.setNavigationBarTitle({
          title: res.data.brandInfo.name,
        })
      } else {
        wx.showToast({
          title: res.errmsg,
          icon: 'none',
          duration: 1500
        })
      }
    });
  },

  // 商品搜索接口
  geList(price,sale){
    console.log(price)
    var that = this;
 
    util.request(api.List, {
      brandId:that.data.id,
      priceStatus:price,
      saleStatus:sale,
    }, 'get').then(function (res) {
      if (res.errno === 0) {
        that.setData({
          goodsList:res.data
        })

      } else {
        wx.showToast({
          title: res.errmsg,
          icon: 'none',
          duration: 1500
        })
      }
    });
  },


  // 综合按钮
  topOne(e){
    var price = e.currentTarget.dataset.price
    var sale = e.currentTarget.dataset.sale
    this.geList(price,sale)
    this.setData({
      one: true,
      two:0,
      three:0,
    })
  },

  // 按价格排序
 getup(e){
   console.log(e)
   var price = e.currentTarget.dataset.price
   var sale = e.currentTarget.dataset.sale
   this.geList(price,sale)
   this.setData({
     one:false,
     two:1,
     three:0
   })
 },

 getup1(e){
  console.log(e)
  var price = e.currentTarget.dataset.price
  var sale = e.currentTarget.dataset.sale
  this.geList(price,sale)
  this.setData({
    one:false,
    two:2,
    three:0
  })
 },

 getup2(e){
  console.log(e)
  var price = e.currentTarget.dataset.price
  var sale = e.currentTarget.dataset.sale
  this.geList(price,sale)
  this.setData({
    one:false,
    two:1,
    three:0
  })
 },

//  按销量
getThree(e){
  console.log(e)
  var price = e.currentTarget.dataset.price
  var sale = e.currentTarget.dataset.sale
  this.geList(price,sale)
  this.setData({
    one:false,
    two:0,
    three:1
  })
},

getThree1(e){
  console.log(e)
  var price = e.currentTarget.dataset.price
  var sale = e.currentTarget.dataset.sale
  this.geList(price,sale)
  this.setData({
    one:false,
    two:0,
    three:2
  })
},

getThree2(e){
  console.log(e)
  var price = e.currentTarget.dataset.price
  var sale = e.currentTarget.dataset.sale
  this.geList(price,sale)
  this.setData({
    one:false,
    two:0,
    three:1
  })
},


  //点击进入详情购买
  onItemClick(e) {
    var goodsid = e.currentTarget.dataset.id;
    util.toClass('/pages/details/details', {
      goodsid: goodsid
    })
  },

  // 跳转
  toSeach(){
    wx.navigateTo({
      url: '/pages/search-index/seach-index?brandId='+this.data.id,
    })
  },

  // 跳转详情
  toSec(){
    wx.navigateTo({
      url: '/pages/shop_listsec/shop_listsec?detail='+this.data.detail,
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 获取商品id
    var id = options.id;
    console.log(id)
    this.getDrandIndex(id)
    this.setData({
      id: id,
    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})